var service_common = require("common.js");

//对外公开的方法
module.exports = {
  getStudentsNums: getStudentsNums,
  setTeacherInfo: setTeacherInfo,
  getTeacherInfo: getTeacherInfo,
  getTeacherMoneyList: getTeacherMoneyList,
  getStudentsList: getStudentsList,
  listenClass: listenClass
}

/**
 * 获取学生数
 */
function getStudentsNums(cb) {
  service_common.fetchData(
    service_common.getUrl("user.getStudentsNums"),
    {
      openid: getApp().globalData.openid
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 设置讲师信息
 */
function setTeacherInfo(cb) {
  service_common.fetchData(
    service_common.getUrl("user.setTeacherInfo"),
    {
      openid: getApp().globalData.openid
    },
    function (res) {
      cb(res);
    },
    "POST"
  )
}

/**
 * 获取讲师信息
 */
function getTeacherInfo(cb) {
  service_common.fetchData(
    service_common.getUrl("user.getTeacherInfo"),
    {
      openid: getApp().globalData.openid
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取学生列表
 */
function getStudentsList(page, cb, all = 1) {
  service_common.fetchData(
    service_common.getUrl("user.getStudentsList"),
    {
      openid: getApp().globalData.openid,
      all: all,
      page: page
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取讲师收益列表
 */
function getTeacherMoneyList(page, cb, all = 1) {
  service_common.fetchData(
    service_common.getUrl("user.getTeacherMoneyList"),
    {
      openid: getApp().globalData.openid,
      all: all,
      page: page
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 学生听课
 */
function listenClass(id, cb) {
  service_common.fetchData(
    service_common.getUrl("teacher.listenClass"),
    {
      openid: getApp().globalData.openid,
      id: id
    },
    function (res) {
      cb(res);
    },
    "POST",true
  )
}